Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.Net.Mail
Imports System.Collections.Generic
Public Class clsMails
    Public Function objEnviarMail(ByVal MailOrigen As String, ByVal MailDestino As String, ByVal MailAsunto As String, _
                    ByVal MailCuerpo As String, ByVal MailUser As String, ByVal MailPassword As String) As Boolean
        Dim res As Boolean = False
        Dim Mail As New System.Net.Mail.MailMessage
        Dim Servidor As New System.Net.Mail.SmtpClient
        Mail.From = New System.Net.Mail.MailAddress(MailOrigen)
        Try
            Mail.To.Add(MailDestino)
        Catch ex As Exception
            Exit Function
        End Try
        Mail.Subject = MailAsunto
        Mail.Body = MailCuerpo
        Mail.IsBodyHtml = True
        Mail.Priority = MailPriority.Normal
        Servidor.Host = "192.168.105.253"
        'Servidor.Port = 8443
        Servidor.Credentials = New System.Net.NetworkCredential(MailUser, MailPassword)

        Try
            Servidor.Send(Mail)
            res = True
        Catch ex As Exception
            Throw ex
        End Try

        Return res
    End Function
    Public Function objEnviarMail(ByVal MailOrigen As String, ByVal MailDestino As List(Of String), ByVal MailAsunto As String, _
                   ByVal MailCuerpo As String, ByVal MailUser As String, ByVal MailPassword As String) As Boolean
        Dim res As Boolean = False
        Dim Mail As New System.Net.Mail.MailMessage
        Dim Servidor As New System.Net.Mail.SmtpClient
        Mail.From = New System.Net.Mail.MailAddress(MailOrigen)
        For Each Item As String In MailDestino
            Mail.To.Add(Item)
        Next
        Mail.Subject = MailAsunto
        Mail.Body = MailCuerpo
        Mail.IsBodyHtml = True
        Mail.Priority = MailPriority.Normal
        Servidor.Host = "172.16.16.6"
        'Servidor.Port = 8443
        Servidor.Credentials = New System.Net.NetworkCredential(MailUser, MailPassword)

        Try
            Servidor.Send(Mail)
            res = True
        Catch ex As Exception
            Throw ex
        End Try

        Return res
    End Function
    Public Function objMosPerMails(ByVal PerCodigo As String, _
                                ByVal MyTrans As SqlTransaction, _
                                ByVal Cn As SqlConnection, Optional ByVal Filtro As String = "") As SqlDataReader


        Dim Sql As String = "Select cPerMaiNombre AS Mail From PerMail Where cPerCodigo in(" & PerCodigo & ")"

        If Filtro <> String.Empty Then
            Sql += " AND cPerMaiNombre LIKE '%" & Filtro & "%'"
        End If

        Dim MiClase As New clsManejadorDatos
        Return MiClase.objExecuteReader(Sql, MyTrans, Cn)
    End Function
    
    Public Function objEnviarMailPublicacion(ByVal MailOrigen As String, ByVal MailDestino As String, ByVal MailAsunto As String, _
                 ByVal MailCuerpo As String, ByVal MailUser As String, ByVal MailPassword As String) As Boolean
        Dim res As Boolean = False
        Dim Mail As New System.Net.Mail.MailMessage
        Dim Servidor As New System.Net.Mail.SmtpClient
        Mail.From = New System.Net.Mail.MailAddress(MailOrigen)
        Mail.To.Add(MailDestino)
        Mail.Subject = MailAsunto
        Mail.Body = MailCuerpo
        Mail.IsBodyHtml = True
        Mail.Priority = MailPriority.Normal
        Servidor.Host = "172.16.16.6"
        Servidor.Credentials = New System.Net.NetworkCredential(MailUser, MailPassword)

        Try
            Servidor.Send(Mail)
            res = True
        Catch ex As Exception
            Throw ex
        End Try

        Return res
    End Function




End Class
